import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../../provide/cart_provider.dart';
import '../../provide/current_index_provider.dart';
import '../../provide/details_info_provider.dart';

class DetailsBottom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var goodsInfo = context.watch<DetailsInfoProvider>().goodsInfo.data.goodInfo;

    var goodsID = goodsInfo.goodsId;
    var goodsName = goodsInfo.goodsName;
    var count = 1;
    var price = goodsInfo.presentPrice;
    var images = goodsInfo.image1;

    return Container(
      color: Colors.white,
      width: ScreenUtil.screenWidth,
      height: ScreenUtil().setHeight(80),
      child: Row(
        children: <Widget>[
          Stack(
            children: <Widget>[
              InkWell(
                onTap: () {
                  context.read<CurrentIndexProvider>().changeIndex(2);
                  Navigator.pop(context);
                },
                child: Container(
                  width: ScreenUtil().setWidth(110),
                  alignment: Alignment.center,
                  child: Icon(
                    Icons.shopping_cart,
                    size: 35,
                    color: Colors.red,
                  ),
                ),
              ),
              Consumer<CartProvider>(
                builder: (context, val, child) {
                  return Positioned(
                    top: 0,
                    right: 10,
                    child: Container(
                      padding: EdgeInsets.fromLTRB(6, 3, 6, 3),
                      decoration: BoxDecoration(
                          color: Colors.pink,
                          border: Border.all(width: 2, color: Colors.white),
                          borderRadius: BorderRadius.circular(12.0)),
                      child: Text(
                        '${val.cartList.length}',
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: ScreenUtil().setSp(22)),
                      ),
                    ),
                  );
                },
              )
            ],
          ),
          Expanded(
            child: InkWell(
              onTap: () async {
                await context
                    .read<CartProvider>()
                    .save(goodsID, goodsName, count, price, images);
              },
              child: Container(
                alignment: Alignment.center,
                height: ScreenUtil().setHeight(80),
                color: Colors.green,
                child: Text(
                  '加入购物车',
                  style: TextStyle(
                      color: Colors.white, fontSize: ScreenUtil().setSp(28)),
                ),
              ),
            ),
          ),
          Expanded(
            child: InkWell(
              onTap: () async {
                await context.read<CartProvider>().remove();
              },
              child: Container(
                alignment: Alignment.center,
                height: ScreenUtil().setHeight(80),
                color: Colors.red,
                child: Text(
                  '马上购买',
                  style: TextStyle(
                      color: Colors.white, fontSize: ScreenUtil().setSp(28)),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
